<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Event/classes/PhpFox_ComponentCalendar.class.php, $Author:  $ */



/** Component for showing calendar
 * @version $Id: PhpFox_ComponentCalendar.class.php 432 2008-04-15 11:51:59Z phpfoxsv $
 * @package module.event
 *   
 */
class PhpFox_Mod_Event_ComponentCalendar extends BaseComponent
{
    function process()
    {
        $oEventItem = $this->_oModule->getItem('Event');
        /* @var $oEventItem PhpFox_Mod_Event_ItemEvent */
        $oEventService = $this->_oModule->getService('Event');
        /* @var $oEventService PhpFox_Mod_Event_ServiceEvent */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = $this->_oModule->getTemplate();
        $oReq = &App::getRequest();

        $oSecurityService->checkPerm('events', array('read_only', 'full'));
        $oSecurityService->checkAccess('events');
        $iMonth = $oReq->getInt('month');
        $iYear = $oReq->getInt('year');
        $sUser = $oSecurityService->getCurrentUserLogin();
        if (!$iMonth || !$iYear)
        {
            $iMonth = date('n');
            $iYear = date('Y');
        }
        $aCalendar = $oEventService->buildCalendar($iMonth, $iYear);
        $aCond = array();
        $iMaxEvents = App::getParam('public.calendar_events');
        $aCond['month'] = 'IN(' . $iMonth . ',0' . $iMonth . ')';
        $aCond['year'] = '= "'.$iYear.'"';
        list($aItems, $iCnt) = $oEventService->getEventList($aCond, 0, 0);
        foreach ($aCalendar as $iKey => $aWeek)
        {
            foreach ($aWeek as $iDay => $sDay)
            {
                if ($iDay != '')
                {
                	$aCalendar[$iKey][$iDay] = $oEventService->getDayEvents($iDay, $aItems, $iMaxEvents);
                }
            }
        }
        list($iPrevMonth, $iPrevYear) = $oEventService->prevMonth($iMonth, $iYear);
        list($iNextMonth, $iNextYear) = $oEventService->nextMonth($iMonth, $iYear);
		$iCurrentMonth = date('n');
		$iCurrentYear = date('Y');
		$iCurrentDay = '';
		if (($iMonth == $iCurrentMonth) && ($iYear == $iCurrentYear))
		{
		    $iCurrentDay = date('j');
		}
        $oTpl->assign(array(
        	'iNextMonth'    => mktime(0, 0, 0, $iNextMonth, 1, $iNextYear),
        	'iPrevMonth'    => mktime(0, 0, 0, $iPrevMonth, 1, $iPrevYear),
        	'iCurrentDay'   => $iCurrentDay,
        	'iCurrentMonth' => mktime(0, 0, 0, $iMonth, 1, $iYear),
        	'aCalendar'     => $aCalendar,
        	'iMaxCount'     => $iMaxEvents + 1,
        ));
        return $oTpl->fetch('Calendar.html');
    }
}

?>